local skels = {}

Fk:loadTranslationTable {
  ["$xiaobai__piyi11"] = "万物万形，其归一也，何由致一？由于无也。",
  ["$xiaobai__piyi12"] = "无状无象，无声无响，故能无所不通，无所不往。"
}

--典中典复数技能（为什么这么多个，万一有个左慈将单独获得其中一个技能呢？）
for i = 1, 30, 1 do
  local name = "xiaobai__piyi" .. i
  local piyi = fk.CreateSkill {
    name = name,
    dynamic_desc = function(self, player, lang)
      local str = ""
      if player:usedSkillTimes(name, Player.HistoryRound) > 0 then
        str = str .. "<b><font color=\"red\">(已使用) </font></b>"
      end
      str = str .. "每轮限一次，你可以【八卦阵】的方式使用「【"
      local cardName = player:getMark(name) ~= 0 and player:getMark(name) or "nullification"
      str = str .. Fk:translate(cardName, "zh_CN") .. "】」，若抵消了其他角色使用的普通锦囊牌，你获得一个单独的“辟易”然后将此“辟易”内的「」改为你抵消的牌名。（每种牌名限获得一个）"
      return str
    end,
  }
  Fk:loadTranslationTable {
    [name] = "辟易",
    [":" .. name] = "每轮限一次，你可以【八卦阵】的方式使用「【无懈可击】」，若抵消了其他角色使用的普通锦囊牌，你获得一个单独的“辟易”然后将此“辟易”内的「」改为你抵消的牌名。（每种牌名限获得一个）",
  }
  piyi:addEffect("viewas", {
    mute = true,
    pattern = ".",
    anim_type = " ",
    prompt = function(self, player, selected_cards, selected)
      local cardName = player:getMark(name) ~= 0 and player:getMark(name) or "nullification"
      return "辟易：是否以【八卦阵】的方式使用【" .. Fk:translate(cardName, "zh_CN") .. "】？"
    end,
    view_as = function(self, player, cards)
      local cardName = player:getMark(name) ~= 0 and player:getMark(name) or "nullification"
      local card = Fk:cloneCard(cardName)
      card.skillName = name
      return card
    end,
    before_use = function(self, player, use)
      local room = player.room
      room:notifySkillInvoked(player, "xiaobai__piyi1")
      player:broadcastSkillInvoke("xiaobai__piyi1")
      local judge = {
        who = player,
        reason = "#eight_diagram_skill",
        pattern = ".|.|heart,diamond",
      }
      room:broadcastPlaySound("./packages/standard_cards/audio/card/eight_diagram")
      room:setEmotion(player, "./packages/standard_cards/image/anim/eight_diagram")
      room:judge(judge)
      if not judge:matchPattern() then
        return name
      end
    end,
    enabled_at_play = function(self, player)
      local cardName = player:getMark(name) ~= 0 and player:getMark(name) or "nullification"
      return player:usedSkillTimes(name, Player.HistoryRound) == 0 and #player:getViewAsCardNames(name, { cardName }) > 0
    end,
    enabled_at_response = function(self, player, response)
      local cardName = player:getMark(name) ~= 0 and player:getMark(name) or "nullification"
      return not response and player:usedSkillTimes(name, Player.HistoryRound) == 0 and
      #player:getViewAsCardNames(name, { cardName }) > 0
    end,
  })
  piyi:addEffect(fk.CardEffectCancelledOut, {
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      local room = player.room
      local effectEvent = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect, true)
      if effectEvent == nil then return end
      local is_from = false
      player.room.logic:getEventsByRule(GameEvent.UseCard, 1, function(e)
        local use = e.data
        if use.responseToEvent == data then
          if use.from == player and use.card.skillName == name then
            if use.responseToEvent.card:isCommonTrick() then
              event:setCostData(self, use.responseToEvent.card.trueName)
              is_from = true
            end
          end
          return true
        end
      end, effectEvent.id)
      for j = 1, 30, 1 do
        local tempName = "xiaobai__piyi" .. j
        if player:hasSkill(tempName) and player:getMark(tempName) == event:getCostData(self)then
          return
        end
      end
      return target ~= player and is_from
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      local room = player.room
      for j = 1, 30, 1 do
        local tempName = "xiaobai__piyi" .. j
        if not player:hasSkill(tempName) then
          room:setPlayerMark(player, tempName, event:getCostData(self))
          room:handleAddLoseSkills(player, tempName)
          break
        end
      end
    end,
  })
  table.insert(skels, piyi)
end

return skels
